/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui;

import javax.microedition.lcdui.Graphics;

/**
 *
 * @author kien.tran
 */
public class LinkItem extends ADetailItem {

    public LinkItem(String id, String title, String text) {
        super(id, title, text);
    }

    public void paint(int x, int y, Graphics g) {
        paint(x, y, g, false);
    }

    public void paint(int x, int y, Graphics g, boolean validate) {
        if (validate && !isPaint(x, y)) {
            return;
        }

        initItem();

        int i = 0, tempX = 0, tempY = 0;

        // paint background
        if (focus) {
            g.setColor(style.getSelectedBgColor());
            g.fillRect(getX(), getY(), width - style.getPadding().getLeftAndRight(), height);
        }

        // paint title
        if (title.length() > 0) {
            tempX = getX() + style.getPadding().getLeft() + titleStyle.getPadding().getLeft();
            tempY = getY() + style.getPadding().getTop() + titleStyle.getPadding().getTop();
            if (focus) {
                for (i = 0; i < titleRows.length; i++) {
                    g.setColor(0x000000);
                    font.getFontBoldItalic().drawString(g, titleRows[i], tempX, tempY + i * (font.getFontBoldItalic().getHeight() + titleStyle.getRowHeight()), Graphics.TOP | Graphics.LEFT);
                }
            } else {
                for (i = 0; i < titleRows.length; i++) {
                    font.getFontBoldItalic().drawString(g, titleRows[i], tempX, tempY + i * (font.getFontBoldItalic().getHeight() + titleStyle.getRowHeight()), Graphics.TOP | Graphics.LEFT);
                }
            }
        }

        // paint value
        if (value.length() > 0) {
            tempX = getX() + style.getPadding().getLeft() + valueStyle.getPadding().getLeft();
            tempY = getY() + style.getPadding().getTop() + titleStyle.getHeight() + valueStyle.getPadding().getTop();
            if (focus) {
                for (i = 0; i < valueRow.length; i++) {
                    g.setColor(0x000000);
                    font.getFontItalic().drawString(g, valueRow[i], tempX, tempY + i * (font.getFontItalic().getHeight() + valueStyle.getPadding().getTop()), Graphics.TOP | Graphics.LEFT);
                }
            } else {
                for (i = 0; i < valueRow.length; i++) {
                    font.getFontItalic().drawString(g, valueRow[i], tempX, tempY + i * (font.getFontItalic().getHeight() + valueStyle.getPadding().getTop()), Graphics.TOP | Graphics.LEFT);
                }
            }
        }
    }
}
